﻿using UnityEngine;
using System.Collections;

public abstract class Unit : MonoBehaviour {

	public enum EStates
	{
		STAND = 0,
		TURN,
		MOVE,
		HIT,
		DESTROY,
		MAX
	}
	protected string _name = null;

	public float _life = 100f;
	protected float _defense = 0f;
	protected float _attack = 0f;
	protected float _attackSpeed = 0f;
	protected float _maxSpeed = 0f;
	protected float _acceleration = 0f;
	protected float _turnSpeed = 0f;
	protected int _moveLevel = 0;
	public HCHexagonController.EType _faction = HCHexagonController.EType.EMPTY;
	public HCHexagonController _hexagon = null;
	[SerializeField] protected AnimationCurve _moveCurve;
	
	protected StateMachine _stateMachine = new StateMachine();
	protected EventListener _eventHandler = new EventListener();
	
	public string UnitName{ get{ return _name; } }
	public float Defence{ get{ return _defense; } set{ _defense = value; } }
	public float Attack{ get{ return _attack; } set{ _attack = value; } }
	public float AttackSpeed{ get{ return _attackSpeed; } set{ _attackSpeed = value; } }
	public float MaxSpeed{ get{ return _maxSpeed; } set{ _maxSpeed = value; } }
	public float Acceleration{ get{ return _acceleration; } set{ _acceleration = value; } }
	public float TurnSpeed{ get{ return _turnSpeed; } set{ _turnSpeed = value; } }
	
	public HCHexagonController.EType Faction{ get{ return _faction; } set{ _faction = value; } }
	public HCHexagonController Hexagon{ get{return _hexagon; } set{ _hexagon = value; }}
	public EventListener EventHandler{ get{ return _eventHandler; } }
	
	
	public abstract void MoveTo(Vector3 _position);
	public virtual bool canMove{get{ return true;}}

	public void Destroy()
	{
		//Effect ();
		_hexagon.Unit = null;
		DestroyImmediate (this);
	}

	public void ApplyDamage(float _value)
	{
		_life -= (_value * _defense);
		if (_life <= 0) 
		{
			Destroy ();
		}
	}
	
}
